package com.fjxd.user.web;

import com.fjxd.user.pojo.vo.MoneyVo;
import com.fjxd.user.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/money")
public class MoneyController {

    @Autowired
    private MoneyService moneyService;

    /*
    * 查询余额
    * */
    @GetMapping("/getMoney/{id}")
    public MoneyVo getMoney(@PathVariable Integer id){
        return moneyService.getMoney(id);
    }


    /*
    * 增加余额
    * */
    @GetMapping("/addMoney/{id}/{money}")
    public boolean addMoney(@PathVariable Integer id,@PathVariable double money){
        return moneyService.addMoney(id,money);
    }

    /*
    * 减少余额
    * */
    @GetMapping("/upMoney/{id}/{money}")
    public boolean upMoney(@PathVariable Integer id, @PathVariable double money)
    {
        MoneyVo moneyVo = moneyService.getMoney(id);
        double money1 = moneyVo.getMoney();
        if (money1>=money)
        {
            return moneyService.upMoney(id, money);
        }
        return false;
    }
}
